package com.youtui.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.youtui.common.constant.ResultMessage;
import com.youtui.common.util.DxSmsUtil;
import com.youtui.common.util.ResultUtil;
import com.youtui.manager.service.ISmsCodeService;

@Controller 
@RequestMapping("/smscode")
public class SmsCodeController extends BaseController{

	@Autowired DxSmsUtil dxSmsUtil;
	@Autowired ISmsCodeService smsCodeService;

	@RequestMapping("/verify.do")
	@ResponseBody
	public ResultMessage loadAccount(String mobile ) throws Exception{
		 
		// 验证码
		int count =smsCodeService.findCodeByMobile(mobile, 1);
		if(count >0){
			return ResultUtil.result(ResultUtil.code_fail, "验证码有效期10分钟，请勿重复请求");
		}
		  
		String code=smsCodeService.insertSmsCode(mobile, 1);  // 登录短信验证码
		
		String message ="您的登录验证码为："+code+",有效期10分钟， 欢迎使用优推互动广告平台！";
		dxSmsUtil.sendSmsMessage_Hex(mobile, message);
		
		return ResultUtil.result(ResultUtil.code_success, "验证码发送成功");
	}
	 
}
